{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "866b1df2-1f0d-4cbe-9546-00eaae998de2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Huawei(_Satphone__name='华为', _Satphone__satelite='北斗+天通')是一个卫星电话? True\n",
      "华为使用北斗+天通卫星线路发送信息: 5G没信号了, 我还有信号!\n",
      "华为使用北斗+天通卫星线路拨打\n",
      "华为使用北斗+天通卫星路线定位: 东经180.0°,北纬90.0°\n",
      "Tesla(_Satphone__name='特拉斯', _Satphone__satelite='starlink')是一个卫星电话? True\n",
      "特拉斯使用starlink卫星线路发送信息: 5G没信号了, 我还有信号!\n",
      "特拉斯使用starlink卫星线路拨打 | 接收电话\n",
      "特拉斯使用starlink卫星路线定位: 东经180.0°,南纬90.0°\n"
     ]
    }
   ],
   "source": [
    "from abc import ABC\n",
    "from dataclasses import dataclass\n",
    "\n",
    "@dataclass\n",
    "class Satphone(ABC):\n",
    "    __name: str\n",
    "    __satelite: str\n",
    "    \n",
    "    @property\n",
    "    def name(self):\n",
    "        return self.__name\n",
    "\n",
    "    @name.setter\n",
    "    def name(self,value):\n",
    "        self.__name = value \n",
    "\n",
    "    @property\n",
    "    def satelite(self):\n",
    "        return self.__satelite\n",
    "\n",
    "    @satelite.setter\n",
    "    def satelite(self, value):\n",
    "        self.__sateline = value\n",
    "\n",
    "    def message(self, m):\n",
    "        print(f'{self.name}使用{self.satelite}卫星线路发送信息: {m}')\n",
    "\n",
    "    def call(self):\n",
    "        print(f'{self.name}使用{self.satelite}卫星线路拨打 | 接收电话')\n",
    "\n",
    "    def _toCoordinates(self, complex):\n",
    "        return f'{\"东\"if complex.real >= 0 else \"西\"}经{abs(complex.real)}°,\\\n",
    "    {\"北\" if complex.imag >= 0 else \"南\"}纬{abs(complex.imag)}°'.replace(\" \",\"\")\n",
    "\n",
    "    def lbs(self, coordinates):\n",
    "         print(f'{self.name}使用{self.satelite}卫星路线定位: {self._toCoordinates(coordinates)}')\n",
    "\n",
    "class Huawei(Satphone):\n",
    "    def __init__(self):\n",
    "        super().__init__(\"华为\",\"北斗+天通\")\n",
    "    \n",
    "    def call(self):\n",
    "        print(f'{self.name}使用{self.satelite}卫星线路拨打')\n",
    "class Tesla(Satphone):\n",
    "    def __init__(self):\n",
    "        super().__init__(\"特拉斯\",\"starlink\")\n",
    "\n",
    "def satphone(phone, coordinates):\n",
    "    print(f'{phone}是一个卫星电话? {isinstance(phone,Satphone)}')\n",
    "    phone.message('5G没信号了, 我还有信号!')\n",
    "    phone.call()\n",
    "    phone.lbs(coordinates)\n",
    "\n",
    "satphone(Huawei(), 180 + 90j)\n",
    "satphone(Tesla(), 180 - 90j)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "063fae14-2d72-4f27-b7aa-63c53ac955b1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
